package com.example.my.android;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyDb extends SQLiteOpenHelper {

    public MyDb(@Nullable Context context) {
        super(context, "student.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //第一次创建数据库的时候调用该方法，创建所有的数据表
        String sql = "CREATE TABLE students(" +
                "   code varchar(20) PRIMARY KEY," +
                "   name varchar(20)," +
                "   age int," +
                "   gender varchar(5)" +
                ");";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
